package juc.CAS.原子类.AtomicLong;

import java.util.concurrent.atomic.AtomicLong;

public class AtomicTest {
    private static volatile AtomicLong sum = new AtomicLong(0);

    public static void main(String[] args) throws InterruptedException {
        for (int j = 0; j < 10; j++) {
            new Thread(() -> {
                for (int i = 0; i < 1000; i++) {
                    add();
                }
            }).start();
        }
        while (Thread.activeCount() > 1) {
            Thread.yield();
        }
        System.out.println(sum.get());
    }

    private static void add() {
        sum.incrementAndGet();
    }
}